package sdk.webview.fmc.com.fmcsdk.check.adapter;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.check.bean.TypeSelectBean;

public class TypeSelectAdapter extends BaseQuickAdapter<TypeSelectBean, BaseViewHolder> {
    public TypeSelectAdapter(@Nullable List<TypeSelectBean> data) {
        super(R.layout.item_type_select, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, TypeSelectBean item) {
        holder.setText(R.id.tv_name, item.getName())
                .setImageResource(R.id.iv_check, item.isSelect() ? R.mipmap.icon_check_red : R.mipmap.icon_select_no);
    }


    public boolean setSelectNo(int position){
        boolean isNoSelect=false;
        for (int i=0;i<getData().size();i++){
            if(!getData().get(i).isSelect()){
                isNoSelect=true;
            }
        }
        notifyDataSetChanged();
        return isNoSelect;
    }

    public void setSelectAll(boolean isAll){
        for (int i=0;i<getData().size();i++){
            getData().get(i).setSelect(isAll);
        }
        notifyDataSetChanged();
    }

    public String getSelectType(){
        boolean isHave=false;
        StringBuilder type= new StringBuilder();
        for (int i=0;i<getData().size();i++){
            if(getData().get(i).isSelect()){
                isHave=true;
                type.append(getData().get(i).getType());
                if(i!=getData().size()-1){
                    type.append(",");
                }
            }
        }
        if(!isHave){
            type= new StringBuilder("");
        }
        return type.toString();
    }


}
